package com.itheima.controller;

import com.itheima.cammon.CommonResult;
import com.itheima.dto.PhoneCodeDto;
import com.itheima.dto.PhoneDto;
import com.itheima.service.UserService;
import com.itheima.vo.LoginVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



/**
 * @author 王同学
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;
    @PostMapping("sendMsg")
    public CommonResult sendMsg(@RequestBody PhoneDto phoneDto){
        boolean res = userService.sendMsg(phoneDto.getPhone());

        return CommonResult.success(res? 200:500,res? "发送成功":"发送失败",null);
    }
    @PostMapping("login")
    public CommonResult login(@RequestBody PhoneCodeDto phoneCodeDto){

        LoginVO res = userService.login(phoneCodeDto);

        return CommonResult.success(200,"登陆成功",res);
    }
    @PostMapping("loginout")
    public CommonResult loginout(){

        return CommonResult.success();
    }

}
